Skip to content

Fix CLI contract: distinct exit codes, version from package.json, Node 18 test runner - #3

Merged
nullcache merged 1 commit into
nullcache:mainfrom
uuzzrm:fix/cli-contract
Aug 17, 2026
Merged

Fix CLI contract: distinct exit codes, version from package.json, Node 18 test runner#3
nullcache merged 1 commit into
nullcache:mainfrom
uuzzrm:fix/cli-contract

Conversation

@uuzzrm

@uuzzrm uuzzrm commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Why this is core

A CLI's exit codes and version output are contracts — scripts and CI wrap corecoder-ts and depend on them. The TS port silently regressed three of them against the Python original and its own engines claim:

  1. Error vs interrupt exit codes were collapsed — the Python original exits 1 on error and 130 on ^C; the TS port returned 130 for both. Any wrapper that checks $? can't tell a crash from a user cancel.
  2. Version was hardcodedsrc/cli.ts shipped const VERSION = '0.1.0' while package.json is the real source of truth; every release bump risks --version drifting.
  3. npm test breaks on the declared Node floornode --test dist/tests/*.test.js relies on the test runner expanding globs, which only landed in Node 21. On Node 18/20 — which engines claims to support — and on Windows cmd (which never expands), the literal pattern is passed through and the run fails.

Changes

Distinct exit codes (src/cli.ts)

  • runTurn now reports whether a null result was a cancellation (aborted) or a failure.
  • New exported turnExitCode(): 0 success, 130 ^C interrupt, 1 error — matching the Python original (KeyboardInterrupt -> 130, Exception -> 1) and POSIX convention (128 + SIGINT).

Version from package.json (src/cli.ts)

  • VERSION (now exported) is read at runtime via createRequire relative to the module file — works both in the repo (dist/src/cli.js -> ../../package.json) and in a published tarball (same layout). A unit test pins it to package.json so drift fails CI.

Cross-version test runner (scripts/run-tests.mjs, package.json)

  • New small runner resolves dist/tests/*.test.js itself and passes explicit paths to node --test — identical behavior on Node 18–24 and every shell, and new test files are picked up automatically (no script edits on adding a test).

Tests (tests/cli.test.ts, 2 new)

  • turnExitCode: 0 / 130 / 1 matrix
  • VERSION equals package.json version

All 26 tests pass (npm test via the new runner); --version prints corecoder-ts 0.1.0; demo exits 0.

@nullcache
nullcache merged commit 8ee5328 into nullcache:main Aug 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants